package com.yingxue.lesson.service.impl;

import com.yingxue.lesson.dao.SysUserDao;
import com.yingxue.lesson.entity.SysUser;
import com.yingxue.lesson.service.HomeService;
import com.yingxue.lesson.service.SysPermissionService;
import com.yingxue.lesson.vo.resp.HomeRespVO;
import com.yingxue.lesson.vo.resp.PermissionRespNodeVO;
import com.yingxue.lesson.vo.resp.UserInfoRespVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chahua
 * @date 2022/4/10 22:28
 **/
@Service
public class HomeServiceImpl implements HomeService {

    @Autowired
    private SysUserDao sysUserDao;

    @Autowired
    private SysPermissionService sysPermissionService;

    @Override
    public HomeRespVO getHome(String userId) {
        // 响应vo
        HomeRespVO homeRespVO=new HomeRespVO();
        List<PermissionRespNodeVO> list = sysPermissionService.permissionTreeList(userId);
        homeRespVO.setMenus(list);
        // 根据用户id获取用户信息：用户id,用户名称，部门id
        SysUser sysUser = sysUserDao.queryById(userId);
        UserInfoRespVO vo=new UserInfoRespVO();
        if(sysUser!=null){
            BeanUtils.copyProperties(sysUser,vo);
            // mock部门名称
            vo.setDeptName("迎学教育总公司");
        }
        homeRespVO.setUserInfoVO(vo);
        return homeRespVO;
    }
}
